<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import echarts from 'echarts'

require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import mapData from './liaoning.json'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      echarts.registerMap('LN',mapData)
      this.chart.setOption({
          title: {
            text: '辽宁省各市退服站数量(20211116)',
            subtext: 'Data from CSV'
          },
          tooltip: {
            trigger: 'item',
            formatter: '{b}<br/>{c}'
          },
          toolbox: {
            show: true,
            orient: 'vertical',
            left: 'right',
            top: 'center',
            feature: {
              dataView: { readOnly: false },
              restore: {},
              saveAsImage: {}
            }
          },
          visualMap: {
            min: 0,
            max: 150,
            text: ['High', 'Low'],
            realtime: false,
            calculable: true,
            inRange: {
              color: ['lightskyblue', 'yellow', 'orangered']
            }
          },
          series: [
            {
              name: '辽宁各市退服站数量',
              type: 'map',
              map: 'LN',
              label: {
                show: true
              },
              data:[
                {
                  "name": "鞍山市",
                  "value": "47"
                },
                {
                  "name": "本溪市",
                  "value": "110"
                },
                {
                  "name": "朝阳市",
                  "value": "5"
                },
                {
                  "name": "大连市",
                  "value": "62"
                },
                {
                  "name": "丹东市",
                  "value": "33"
                },
                {
                  "name": "抚顺市",
                  "value": "7"
                },
                {
                  "name": "阜新市",
                  "value": "25"
                },
                {
                  "name": "葫芦岛市",
                  "value": "8"
                },
                {
                  "name": "锦州市",
                  "value": "5"
                },
                {
                  "name": "辽阳市",
                  "value": "16"
                },
                {
                  "name": "沈阳市",
                  "value": "39"
                },
                {
                  "name": "铁岭市",
                  "value": "23"
                },
                {
                  "name": "营口市",
                  "value": "13"
                }
              ]
            }
          ]
        }
      )
    }
  }
}
</script>
